// 确认矩阵是否可以相乘。只有第一个矩阵的列的个数等于第二个矩阵的行的个数，这样的两个矩阵才能相乘。

function matrixMultiply(m1, m2) {
    if (m1[0].length !== m2.length) {
        return "不符合矩阵乘法规则！";
    }

    let matrix = [];
    for (let i = 0; i < m1.length; i++) {
        matrix[i] = [];
        for (let j = 0; j < m2[0].length; j++) {
            matrix[i][j] = 0;
            for (let k = 0; k < m2.length; k++) {
                matrix[i][j] += m1[i][k] * m2[k][j];
            }
        }
    }
    return matrix;
}

let matrix1 = [[1, 2, 3, 4]];
let matrix2 = [[1], [2], [3], [4]];
let res1 = matrixMultiply(matrix1, matrix2);
console.log(res1);

let m3 = [[1, 2, 3, 4]];
let m4 = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]];
let res2 = matrixMultiply(m3, m4);
console.log(res2);

let m5 = [[4, 3, 2, 1], [4, 3, 2, 1], [4, 3, 2, 1], [4, 3, 2, 1]];
let m6 = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]];
let res3 = matrixMultiply(m5, m6);
console.log(res3);
